package tests;

import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;

import mailsystem.Mailbox;
import mailsystem.persistance.MailsystemPersistance;
import mailsystem.persistance.database.ContactDB;
import mailsystem.persistance.database.MailBoxDB;

import org.junit.Before;
import org.junit.Test;

/**
 * @author pablo
 *
 */
public class ContactDBTest {
	ContactDB contacts;
	Mailbox box1, box2;
	MailsystemPersistance persistanceMock = mock(MailsystemPersistance.class);
	
	@Before
	public void doBefore()
	{
		MailBoxDB boxes;
		
		contacts = new ContactDB(persistanceMock);
		contacts.changeToTestMode();
		boxes = new MailBoxDB(persistanceMock);
		boxes.changeToTestMode();
		box1 = boxes.listAll().get(0);
		box2 = boxes.listAll().get(1);		
	}

	@Test
	public void testAdd() {
		contacts.delete(box1, box2);
		int before = contacts.listAll(box1).size();		
		contacts.add(box1, box2);
		int after = contacts.listAll(box1).size();
		
		assertEquals(before + 1, after);
	}

	@Test
	public void testDelete() {
		int before = contacts.listAll(box1).size();		
		contacts.delete(box1, box2);
		int after = contacts.listAll(box1).size();
		
		assertEquals(before - 1, after);
	}

	@Test
	public void testListAll() {
		contacts.delete(box1, box2);
		int before = contacts.listAll(box1).size();		
		contacts.add(box1, box2);
		int after = contacts.listAll(box1).size();
		
		assertEquals(before + 1, after);
	}

}
